<template>
	<view :class="isDark?'darkBg':''">
		<cu-custom :bgColor="isDark?'bg-black':'bg-orange'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">打卡信息</block>
		</cu-custom>
		<view style="height: 545rpx; background-size: cover;  background-position: center;"
			:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">
			<ad unit-id="adunit-b1c61a406515258a" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
		</view>
		<view :class="isDark?'dark':''">
			<view class="cu-bar  solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
				<view class="action">
					<text class="cuIcon-titles text-orange"></text> 打卡信息
				</view>
			</view>
			<view class="margin  padding radius shadow-lg" :class="isDark?'darkIn':'bg-white'">
				<form class="form" @submit="formSubmit">
					<view class="cu-form-group " :class="isDark?'darkIn':'light'">
						<view class="title">地址</view>
						<textarea name="smallPlace" placeholder="例如:广东省深圳市南山区深圳大学" :value="smallPlace"></textarea>

					</view>
					<view class="cu-form-group " :class="isDark?'darkIn':'light'">
						<view class="title">省</view>
						<input name="sfInfo" placeholder="例如:广东省" :value="sfInfo"></input>

					</view>
					<view class="cu-form-group " :class="isDark?'darkIn':'light'">

						<view class="title">市</view>
						<input name="sInfo" placeholder="例如:深圳市" :value="sInfo"></input>

					</view>
					<view class="cu-form-group " :class="isDark?'darkIn':'light'">

						<view class="title">区</view>
						<input name="qInfo" placeholder="例如:南山区" :value="qInfo"></input>
					</view>
					<view class="cu-bar btn-group" :class="isDark?'darkIn':'light'">
						<button class="cu-btn bg-grey round lg" form-type="submit">{{loginButton}}</button>
						<button class="cu-btn bg-red round lg" @click="clear">清除信息</button>
					</view>
				</form>
			</view>
		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				smallPlace: '',
				sfInfo: '',
				sInfo: '',
				qInfo: '',
				loginButton: '保存',
				isDark: this.isDark,

			}
		},
		onShow() {
			let _this = this

			_this.smallPlace = _this.$store.state.internshipPlace.smallPlace
			_this.sfInfo = _this.$store.state.internshipPlace.sfInfo
			_this.sInfo = _this.$store.state.internshipPlace.sInfo
			_this.qInfo = _this.$store.state.internshipPlace.qInfo
		},

		methods: {
			clear: function() {
				this.$store.commit("internshipPlace", {})

				uni.showToast({
					icon: 'none',
					title: '清除成功',
					duration: 2000
				});
			},
			formSubmit: function(e) {

				let _this = this
				var formdata = e.detail.value
				let form = {
					smallPlace: formdata.smallPlace,
					sfInfo: formdata.sfInfo,
					sInfo: formdata.sInfo,
					qInfo: formdata.qInfo
				}
				if (formdata.smallPlace.indexOf('省') == -1) {
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【省】',
						duration: 2000
					});
					return
				}
				if (formdata.smallPlace.indexOf('市') == -1) {
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【市】',
						duration: 2000
					});
					return
				}
				if (formdata.smallPlace.indexOf('区') == -1) {
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【区】',
						duration: 2000
					});
					return
				}
				if (formdata.sfInfo.indexOf('省') == -1) {
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【省】',
						duration: 2000
					});
					return
				}
				if (formdata.sInfo.indexOf('市') == -1) {
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【市】',
						duration: 2000
					});
					return
				}
				if(formdata.qInfo.indexOf('区')==-1){
					uni.showToast({
						icon: 'none',
						title: '地址格式错误没含【区】',
						duration: 2000
					});
					return
				}
				if (formdata.smallPlace.indexOf(formdata.sfInfo) == -1) {
					uni.showToast({
						icon: 'none',
						title: '省份信息不相同',
						duration: 2000
					});
					return
				}
				if(formdata.smallPlace.indexOf(formdata.sInfo)==-1){
					uni.showToast({
						icon: 'none',
						title: '市的信息不相同',
						duration: 2000
					});
					return
				}
				if(formdata.smallPlace.indexOf(formdata.qInfo)==-1){
					uni.showToast({
						icon: 'none',
						title: '区的信息不相同',
						duration: 2000
					});
					return
				}
				
				_this.$store.commit("internshipPlace", form)
				uni.showToast({
					icon: 'none',
					title: '保存成功',
					duration: 2000
				});
			},

		}

	}
</script>

<style>
	.form {
		margin: 10rpx;
	}

	.imgCodeSrc {
		margin-top: 30rpx;
	}

	.viewInput {
		margin-left: 30rpx;
		margin-bottom: 20rpx;
	}

	.uni-form-item .title {
		padding: 20rpx 0;
	}

	.input {
		border: 1px solid #ccc;
		border-radius: 3px;
		margin-right: 20rpx;
		font-size: 17px;
		font-family: "Microsoft soft";
		padding: 7px 7px;
	}
</style>
